package br.com.hmm.businesslogic;

import java.util.ArrayList;
import java.util.List;

import br.com.hmm.dao.FormulaDAO;
import br.com.hmm.entidade.Formula;

public class FormulaService {
	
	private FormulaService(){
		
	}
	
	/**
	 * 
	 * @param formula
	 * @return
	 * @throws Exception 
	 */
	public static boolean inserir(Formula formula) throws Exception{
		try{
			FormulaDAO fDao = new FormulaDAO();
			if(fDao.inserir(formula) == true){
				return true;
			}
		}catch (Exception e) {
			throw new Exception(e.getMessage());
		}
		
		return false;
	}
	
	/**
	 * 
	 * @param formula
	 * @return
	 * @throws Exception 
	 */
	public static boolean atualizar(Formula formula) throws Exception{
		try{
			FormulaDAO fDao = new FormulaDAO();
			if(fDao.update(formula) == true){
				return true;
			}
		}catch (Exception e) {
			throw new Exception(e.getMessage());
		}
		
		return false;
	}
	
	/**
	 * 
	 * @param formula
	 * @return
	 * @throws Exception 
	 */
	public static boolean delete(Formula formula) throws Exception{
		try{
			FormulaDAO fDao = new FormulaDAO();
			if(fDao.delete(formula) == true){
				return true;
			}			
		}catch(Exception e){
			throw new Exception(e.getMessage());
		}
		
		return false;
	}
	 
	/**
	 * 
	 * @param formula
	 * @return
	 * @throws Exception 
	 */
	public static Formula findById (Formula formula) throws Exception{
		try{
			FormulaDAO fDao = new FormulaDAO();
			Formula f = fDao.findById(formula);
			if(f != null){
				return f;
			}				
			}catch (Exception e) {
				throw new Exception(e.getMessage());
			}
			return null;
		}
	
	/**
	 * 
	 * @return
	 * @throws Exception 
	 */
	public static List<Formula> findAll() throws Exception{
		try{
			FormulaDAO fDao = new FormulaDAO();
			List<Formula> fl = new ArrayList<Formula>();
			fl = fDao.findAll();
			if(fl != null){
				return fl;
			}
		}catch(Exception e){
			throw new Exception(e.getMessage());
		}
		
		return null;
	}
	

}
